/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package XMLManager;

import Database.XMLManager.XMLConfigurationFiles;
import exceptions.DatabaseException;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author Marcello Maggioni
 */
public class XMLConfiguration {
    
    private XMLConfigurationFiles xcf;
    
    public XMLConfiguration() {
        xcf = (XMLConfigurationFiles) XMLConfigurationFiles.getDefaultInstance("D:\\tests");
    }

    // TODO add test methods here.
    // The methods must be annotated with annotation @Test. For example:
    //
    // @Test
    // public void hello() {}

    @Test
    public void configureSystem() {
        try {
            xcf.setEMailAddress(null, "test@email.tk");
            xcf.setServer(null, "server.bigone.tk");
            assertTrue(xcf.getEMailAddress(null).equals("test@email.tk"));
            assertTrue(xcf.getServer(null).equals("server.bigone.tk"));
            xcf.setEMailAddress(null, "test2@email.tk");
            xcf.setServer(null, "server2.bigone.tk");
            assertFalse(xcf.getEMailAddress(null).equals("test@mail.tk"));
            assertFalse(xcf.getServer(null).equals("server.bigone.tk"));
            assertTrue(xcf.getEMailAddress(null).equals("test2@email.tk"));
            assertTrue(xcf.getServer(null).equals("server2.bigone.tk"));
            assertFalse(xcf.getSpamCheck(null));
            xcf.setSpamCheck(null, true);
            assertTrue(xcf.getSpamCheck(null));
            xcf.setSpamCheck(null, false);
            assertFalse(xcf.getSpamCheck(null));
            xcf.removeConfiguration(null);
        } catch (DatabaseException ex) {
            fail();
        }
    }
    
    @Test
    public void configureUsers() {
        try {
            xcf.setEMailAddress("user1", "user1@email.tk");
            xcf.setServer("user1", "server.smallone.tk");
            assertFalse(xcf.getServerAuthMode("user1"));
            xcf.setServerAuthMode("user1", true);
            assertTrue(xcf.getServerAuthMode("user1"));
            xcf.setServerAuthMode("user1", false);
            assertFalse(xcf.getServerAuthMode("user1"));
            assertTrue(xcf.getEMailAddress("user1").equals("user1@email.tk"));
            assertTrue(xcf.getServer("user1").equals("server.smallone.tk"));
            xcf.removeConfiguration("user1");
        } catch (DatabaseException ex) {
            fail();
        }
    }
}